package io.renren.modules.business.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.business.entity.BusProjectEntity;
import io.renren.modules.business.service.BusProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

/**
 * 项目管理
 *
 * @author liao mengqing
 */
@RestController
@RequestMapping("business/project")
public class BusProjectController {
    @Autowired
    private BusProjectService busProjectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:project:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = busProjectService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 根据项目编码获取项目信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:project:info")
    public R info(@PathVariable("id") Long id){
        List<Map<String, Object>> list = busProjectService.queryPageById(id);
        return R.ok().put("busProject", list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:project:save")
    public R save(@RequestBody BusProjectEntity busProject){
        busProject.setProjectScore(0.0);
        busProjectService.save(busProject);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:project:update")
    public R update(@RequestBody BusProjectEntity busProeject){
        busProjectService.updateProject(busProeject);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:project:delete")
    public R delete(@RequestBody Long[] ids){
        busProjectService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
